/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.imgs;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random;

/**
 * <p>Project: javaseapp - Img10
 * <p>Powered by webrx On 2021-08-16 11:02:02
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Img10 {
    public static void main(String[] args) throws IOException {
        int w = 160, h = 60, t = 2;
        var i = new BufferedImage(w, h, t);
        var g = i.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_GASP);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
        for (int i1 = 0; i1 < 3; i1++) {
            paint(g, w, h);
        }
        ImageIO.write(i, "png", new File("c:/ok.png"));
        Runtime run = Runtime.getRuntime();
        run.exec("cmd /k start c:/ok.png");
    }

    public static void paint(Graphics2D g, int w, int h) {
        Random rand = new Random();
        g.setStroke(new BasicStroke(rand.nextInt(3) + 3));
        g.setColor(new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256), rand.nextInt(5) + 1));//设置画线的颜色
        double y = 0;
        double x = 0;
        int a = rand.nextInt(50) + 10;
        int b = rand.nextInt(15) + 5;
        int c = rand.nextInt(150) + 30;

        //一个周期
        for (x = 0; x <= w; x += 0.1) {
            y = Math.sin(x * Math.PI / c);//转化为弧度,1度=π/180弧度
            //y = (200 + 5 * y);//便于在屏幕上显示
            y = (a + b * y);
            //g.drawString(".",(int)x,(int)y);//用这种方式也可以
            g.drawLine((int) x, (int) y, (int) x, (int) y);//画点
        }
    }
}
